package com.ruoyi.shop.member.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.shop.member.mapper.ShopMemberTraceMapper;
import com.ruoyi.shop.common.utils.ShopUtils;
import com.ruoyi.shop.member.domain.ShopMemberTrace;
import com.ruoyi.shop.member.service.IShopMemberTraceService;

/**
 * 会员轨迹Service业务层处理
 * 
 * @author xuxiang
 * @date 2023-06-13
 */
@Service
public class ShopMemberTraceServiceImpl implements IShopMemberTraceService {
	@Autowired
	private ShopMemberTraceMapper shopMemberTraceMapper;

	/**
	 * 查询会员轨迹
	 * 
	 * @param traceId 会员轨迹主键
	 * @return 会员轨迹
	 */
	@Override
	public ShopMemberTrace selectTraceById(Long traceId) {
		return shopMemberTraceMapper.selectTraceById(traceId);
	}

	/**
	 * 查询会员轨迹列表
	 * 
	 * @param shopMemberTrace 会员轨迹
	 * @return 会员轨迹
	 */
	@Override
	public List<ShopMemberTrace> selectTraceList(ShopMemberTrace shopMemberTrace) {
		List<ShopMemberTrace> lists=shopMemberTraceMapper.selectTraceList(shopMemberTrace);
		lists.forEach(trace -> trace.setImage(ShopUtils.getAbsoluteUrl(trace.getImage())));
		return lists;
	}

	/**
	 * 新增会员轨迹
	 * 
	 * @param shopMemberTrace 会员轨迹
	 * @return 结果
	 */
	@Override
	public int insertTrace(ShopMemberTrace shopMemberTrace) {
		shopMemberTrace.setCreateTime(DateUtils.getNowDate());
		return shopMemberTraceMapper.insertTrace(shopMemberTrace);
	}

	/**
	 * 修改会员轨迹
	 * 
	 * @param shopMemberTrace 会员轨迹
	 * @return 结果
	 */
	@Override
	public int updateTrace(ShopMemberTrace shopMemberTrace) {
		shopMemberTrace.setUpdateTime(DateUtils.getNowDate());
		return shopMemberTraceMapper.updateTrace(shopMemberTrace);
	}

	/**
	 * 删除会员轨迹
	 * 
	 * @param traceId 主键
	 * @return 结果
	 */
	@Override
	public int deleteTraceById(Long traceId) {
		return shopMemberTraceMapper.deleteTraceById(traceId);
	}

	/**
	 * 批量删除会员轨迹
	 * 
	 * @param memberId 会员ID
	 * @return 结果
	 */
	@Override
	public int deleteTraceByMember(Long memberId) {
		return shopMemberTraceMapper.deleteTraceByMember(memberId);
	}

}
